package project5;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

/**
 * This class takes in the list of the words that are marked as stop words.
 * 
 * @author surabhi
 */
public class StopWordProcessor
{
	/** The accumulated stop words read from the stop word file. */
	ArrayList<String> stopWordArray ;

	/**
	 * Reads the stop words from the file into an ArrayList and returns it.
	 * 
	 * @param stopWordFilePath The path to the file containing the stop words.
	 * @return stopWordArray The array containing the stop words.
	 */
	public ArrayList<String> createStopWordArrayList(String stopWordFilePath)
	{
		stopWordArray = new ArrayList<String>();
		
		if (null == stopWordFilePath)
		{
			return new ArrayList<String>();
		}

		try
		{
			BufferedReader in = new BufferedReader(new FileReader(stopWordFilePath));
			String stopWord;
			
			while((stopWord = in.readLine())!=null)
			{				
				stopWordArray.add(stopWord);
			}
		}
		catch (FileNotFoundException e)
		{
			System.out.println("ERROR: unable to process input file.");
			System.exit(0);
		}
		catch (IOException e)
		{
			System.out.println("ERROR: unexpected error encountered during file read.");           
		}
		
		return stopWordArray;
	}
}
